#include<t_stdio.h>
#include<t_file.h>
#include<stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <arpa/inet.h>
#include<unistd.h>
#include<time.h>
#include<pthread.h>
#include <string.h>

#define bufferlen 1024 //发送/接收数据缓冲区大小
#define server_port 8888 //端口

int main(int argc ,char * argv[]){
    int s;
    struct sockaddr_in server_addr;
    char buf[bufferlen];
    int n=0;

    //建立套接字
    s = socket(AF_INET , SOCK_STREAM , 0);
    //初始化
    memset(&server_addr , 0 , sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = htons(INADDR_ANY);
    server_addr.sin_port = htons(server_port);

    //连接服务器
    connect(s, (struct sockaddr *)&server_addr , sizeof(server_addr));

    memset(buf , 0 , bufferlen);
    strcpy(buf,"TIME");
    //发送数据
    send(s, buf , strlen(buf) , 0);
    memset(buf , 0 , bufferlen);
    //接收消息
    n = recv(s , buf , bufferlen , 0);

    //打印消息
    if(n > 0){
        printf("TIME : %s\n",buf);
    }

    close(s);

    return 0;
}